home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mintman / filesys.h < prev    next >
C/C++ Source or Header  |  1991-10-28  |  12KB  |  382 lines

  1. /*
  2.  * NOTE: This file only works if sizeof(int) == 2!
  3.  *
  4.  * Copyright 1991 Eric R. Smith. This file may be re-distributed freely
  5.  * so long as this notice remains intact.
  6.  */
  7.  
  8. #ifndef _filesys_h
  9. #define _filesys_h
  10.  
  11. #ifndef P_
  12. # ifdef __STDC__
  13. #  define P_(x) x
  14. # else
  15. #  define P_(x) ()
  16. # endif
  17. #endif
  18.  
  19. #define NAME_MAX 32
  20. #define PATH_MAX 128
  21.  
  22. struct filesys;        /* forward declaration */
  23. struct devdrv;        /* ditto */
  24.  
  25. typedef struct f_cookie {
  26.     struct filesys *fs;    /* filesystem that knows about this cookie */
  27.     unsigned short    dev;        /* device info (e.g. Rwabs device number) */
  28.     unsigned short    aux;        /* extra data that the file system may want */
  29.     long    index;        /* this+dev uniquely identifies a file */
  30. } fcookie;
  31.  
  32. /* structure for opendir/readdir/closedir */
  33. typedef struct dirstruct {
  34.     fcookie fc;        /* cookie for this directory */
  35.     unsigned short    index;        /* index of the current entry */
  36.     unsigned short    flags;        /* flags (e.g. tos or not) */
  37. #define TOS_SEARCH    0x01
  38.     char    fsstuff[60];    /* anything else the file system wants */
  39.                 /* NOTE: this must be at least 45 bytes */
  40. } DIR;
  41.  
  42. /* structure for getxattr */
  43. typedef struct xattr {
  44.     unsigned short    mode;
  45. /* file types */
  46. #define S_IFMT    0170000        /* mask to select file type */
  47. #define S_IFCHR    0020000        /* BIOS special file */
  48. #define S_IFDIR    0040000        /* directory file */
  49. #define S_IFREG 0100000        /* regular file */
  50. #define S_IFIFO 0120000        /* FIFO */
  51. #define S_IMEM    0140000        /* memory region or process */
  52. #define S_IFLNK    0160000        /* symbolic link */
  53.  
  54. /* file access modes for user, group, and other*/
  55. #define S_IRUSR    0400
  56. #define S_IWUSR 0200
  57. #define S_IXUSR 0100
  58. #define S_IRGRP 0040
  59. #define S_IWGRP    0020
  60. #define S_IXGRP    0010
  61. #define S_IROTH    0004
  62. #define S_IWOTH    0002
  63. #define S_IXOTH    0001
  64. #define DEFAULT_DIRMODE (0777)
  65. #define DEFAULT_MODE    (0666)
  66.     long    index;
  67.     unsigned short    dev;
  68.     unsigned short    reserved1;
  69.     unsigned short    nlink;
  70.     unsigned short    uid;
  71.     unsigned short    gid;
  72.     long    size;
  73.     long    blksize, nblocks;
  74.     short    mtime, mdate;
  75.     short    atime, adate;
  76.     short    ctime, cdate;
  77.     short    attr;
  78.     short    reserved2;
  79.     long    reserved3[2];
  80. } XATTR;
  81.  
  82. typedef struct fileptr {
  83.     short    links;        /* number of copies of this descriptor */
  84.     unsigned short    flags;        /* file open mode and other file flags */
  85.     long    pos;        /* position in file */
  86.     long    devinfo;    /* device driver specific info */
  87.     fcookie    fc;        /* file system cookie for this file */
  88.     struct devdrv *dev; /* device driver that knows how to deal with this */
  89.     struct fileptr *next; /* link to next fileptr for this file */
  90. } FILEPTR;
  91.  
  92. typedef struct devdrv {
  93.     long (*open)    P_((FILEPTR *f));
  94.     long (*write)    P_((FILEPTR *f, char *buf, long bytes));
  95.     long (*read)    P_((FILEPTR *f, char *buf, long bytes));
  96.     long (*lseek)    P_((FILEPTR *f, long where, int whence));
  97.     long (*ioctl)    P_((FILEPTR *f, int mode, void *buf));
  98.     long (*datime)    P_((FILEPTR *f, short *timeptr, int rwflag));
  99.     long (*close)    P_((FILEPTR *f));
  100.     long (*select)    P_((FILEPTR *f, long proc, int mode));
  101.     void (*unselect) P_((FILEPTR *f, long proc, int mode));
  102. } DEVDRV;
  103.  
  104. typedef struct filesys {
  105.     struct    filesys    *next;    /* link to next file system on chain */
  106.     long    fsflags;
  107. #define FS_KNOPARSE    0x01    /* kernel shouldn't do parsing */
  108. #define FS_CASESENSITIVE    0x02    /* file names are case sensitive */
  109. #define FS_NOXBIT    0x04    /* if a file can be read, it can be executed */
  110.  
  111.     long    (*root) P_((int drv, fcookie *fc));
  112.     long    (*lookup) P_((fcookie *dir, char *name, fcookie *fc));
  113.     long    (*creat) P_((fcookie *dir, char *name, unsigned mode,
  114.                 int attrib, fcookie *fc));
  115.     DEVDRV *(*getdev) P_((fcookie *fc, long *devspecial));
  116.     long    (*getxattr) P_((fcookie *fc, XATTR *xattr));
  117.     long    (*chattr) P_((fcookie *fc, int attr));
  118.     long    (*chown) P_((fcookie *fc, int uid, int gid));
  119.     long    (*chmode) P_((fcookie *fc, unsigned mode));
  120.     long    (*mkdir) P_((fcookie *dir, char *name, unsigned mode));
  121.     long    (*rmdir) P_((fcookie *dir, char *name));
  122.     long    (*remove) P_((fcookie *dir, char *name));
  123.     long    (*getname) P_((fcookie *relto, fcookie *dir, char *pathname));
  124.     long    (*rename) P_((fcookie *olddir, char *oldname,
  125.                 fcookie *newdir, char *newname));
  126.     long    (*opendir) P_((DIR *dirh, int tosflag));
  127.     long    (*readdir) P_((DIR *dirh, char *nm, int nmlen, fcookie *fc));
  128.     long    (*rewinddir) P_((DIR *dirh));
  129.     long    (*closedir) P_((DIR *dirh));
  130.     long    (*pathconf) P_((fcookie *dir, int which));
  131.     long    (*dfree) P_((fcookie *dir, long *buf));
  132.     long    (*writelabel) P_((fcookie *dir, char *name));
  133.     long    (*readlabel) P_((fcookie *dir, char *name, int namelen));
  134.     long    (*symlink) P_((fcookie *dir, char *name, char *to));
  135.     long    (*readlink) P_((fcookie *dir, char *buf, int len));
  136.     long    (*hardlink) P_((fcookie *fromdir, char *fromname,
  137.                 fcookie *todir, char *toname));
  138.     long    (*fscntl) P_((fcookie *dir, char *name, int cmd, long arg));
  139.     long    (*dskchng) P_((int drv));
  140.     long    zero;
  141. } FILESYS;
  142.  
  143. /*
  144.  * this is the structure passed to loaded file systems to tell them
  145.  * about the kernel
  146.  */
  147.  
  148. typedef long (*_LongFunc)();
  149.  
  150. struct kerinfo {
  151.     short    maj_version;    /* kernel version number */
  152.     short    min_version;    /* minor kernel version number */
  153.     unsigned short default_mode;    /* default file access mode */
  154.     short    reserved1;    /* room for expansion */
  155.  
  156. /* OS functions */
  157.     _LongFunc *bios_tab;     /* pointer to the BIOS entry points */
  158.     _LongFunc *dos_tab;    /* pointer to the GEMDOS entry points */
  159.  
  160. /* media change vector */
  161.     void    (*drvchng) P_((int));
  162.  
  163. /* Debugging stuff */
  164.     void    (*trace) P_((char *, ...));
  165.     void    (*debug) P_((char *, ...));
  166.     void    (*alert) P_((char *, ...));
  167.     void    (*fatal) P_((char *, ...));
  168.  
  169. /* memory allocation functions */
  170.     void *    (*kmalloc) P_((long));
  171.     void    (*kfree) P_((void *));
  172.     void *    (*umalloc) P_((long));
  173.     void    (*ufree) P_((void *));
  174.  
  175. /* utility functions for string manipulation */
  176.     int    (*strnicmp) P_((char *, char *, int));
  177.     int    (*stricmp) P_((char *, char *));
  178.     char *    (*strlwr) P_((char *));
  179.     char *    (*strupr) P_((char *));
  180.     int    (*sprintf) P_((char *, char *, ...));
  181.  
  182. /* utility functions for manipulating time */
  183.     void    (*millis_time) P_((unsigned long, short *));
  184.     long    (*unixtim) P_((unsigned, unsigned));
  185.     long    (*dostim) P_((long));
  186.  
  187. /* utility functions for dealing with pauses */
  188.     void    (*nap) P_((unsigned));
  189.     void    (*sleep) P_((int que, long cond));
  190.     void    (*wake) P_((int que, long cond));
  191.     void    (*wakeselect) P_((long param));
  192.  
  193. /* file system utility functions */
  194.     int    (*denyshare) P_((FILEPTR *, FILEPTR *));
  195.  
  196. /* reserved for future use */
  197.     long    res2[10];
  198. };
  199.  
  200. /* flags for open() modes */
  201. #define O_RWMODE      0x03    /* isolates file read/write mode */
  202. #    define O_RDONLY    0x00
  203. #    define O_WRONLY    0x01
  204. #    define O_RDWR    0x02
  205. #    define O_EXEC    0x03    /* execute file; used by kernel only */
  206.  
  207. #define O_SHMODE    0x70    /* isolates file sharing mode */
  208. #    define O_COMPAT    0x00    /* compatibility mode */
  209. #    define O_DENYRW    0x10    /* deny both read and write access */
  210. #    define O_DENYW    0x20    /* deny write access to others */
  211. #    define O_DENYR    0x30    /* deny read access to others */
  212. #    define O_DENYNONE 0x40    /* don't deny any access to others */
  213.  
  214. #define O_NOINHERIT    0x80    /* this is currently ignored by MiNT */
  215.  
  216. #define O_NDELAY    0x100    /* don't block for i/o on this file */
  217. #define O_CREAT        0x200    /* create file if it doesn't exist */
  218. #define O_TRUNC        0x400    /* truncate file to 0 bytes if it does exist */
  219. #define O_EXCL        0x800    /* fail open if file exists */
  220.  
  221. #define O_USER        0x0fff    /* isolates user-settable flag bits */
  222.  
  223. /* kernel mode bits -- the user can't set these! */
  224. #define O_BIOS        0x2000
  225. #define O_HEAD        0x4000
  226. #define O_LOCK        0x8000
  227.  
  228. /* GEMDOS file attributes */
  229.  
  230. /* macros to be applied to FILEPTRS to determine their type */
  231. #define is_bios(f) (f->flags & O_BIOS)
  232.  
  233. /* lseek() origins */
  234. #define    SEEK_SET    0        /* from beginning of file */
  235. #define    SEEK_CUR    1        /* from current location */
  236. #define    SEEK_END    2        /* from end of file */
  237.  
  238. /* The requests for Dpathconf() */
  239. #define DP_IOPEN    0    /* internal limit on # of open files */
  240. #define DP_MAXLINKS    1    /* max number of hard links to a file */
  241. #define DP_PATHMAX    2    /* max path name length */
  242. #define DP_NAMEMAX    3    /* max length of an individual file name */
  243. #define DP_ATOMIC    4    /* # of bytes that can be written atomically */
  244. #define DP_TRUNC    5    /* file name truncation behavior */
  245. #    define    DP_NOTRUNC    0    /* long filenames give an error */
  246. #    define    DP_AUTOTRUNC    1    /* long filenames truncated */
  247. #    define    DP_DOSTRUNC    2    /* DOS truncation rules in effect */
  248.  
  249. #define DP_MAXREQ    5    /* highest legal request */
  250.  
  251. /* Dpathconf and Sysconf return this when a value is not limited
  252.    (or is limited only by available memory) */
  253.  
  254. #define UNLIMITED    0x7fffffffL
  255.  
  256. /* various character constants and defines for TTY's */
  257. #define MiNTEOF 0x0000ff1a    /* 1a == ^Z */
  258.  
  259. /* defines for tty_read */
  260. #define RAW    0
  261. #define COOKED    0x1
  262. #define NOECHO    0
  263. #define ECHO    0x2
  264.  
  265. /* constants for various Fcntl commands */
  266. /* constants for Fcntl calls */
  267. #define F_DUPFD        0        /* handled by kernel */
  268. #define F_GETFD        1        /* handled by kernel */
  269. #define F_SETFD        2        /* handled by kernel */
  270. #    define FD_CLOEXEC    1    /* close on exec flag */
  271.  
  272. #define F_GETFL        3        /* handled by kernel */
  273. #define F_SETFL        4        /* handled by kernel */
  274. #define F_GETLK        5
  275. #define F_SETLK        6
  276.  
  277. #define FSTAT        (('F'<< 8) | 0)    /* handled by kernel */
  278. #define FIONREAD    (('F'<< 8) | 1)
  279. #define FIONWRITE    (('F'<< 8) | 2)
  280. #define TIOCGETP    (('T'<< 8) | 0)
  281. #define TIOCSETP    (('T'<< 8) | 1)
  282. #define TIOCSETN    TIOCSETP
  283. #define TIOCGETC    (('T'<< 8) | 2)
  284. #define TIOCSETC    (('T'<< 8) | 3)
  285. #define TIOCGLTC    (('T'<< 8) | 4)
  286. #define TIOCSLTC    (('T'<< 8) | 5)
  287. #define TIOCGPGRP    (('T'<< 8) | 6)
  288. #define TIOCSPGRP    (('T'<< 8) | 7)
  289. #define TIOCFLUSH    (('T'<< 8) | 8)
  290. #define TIOCSTOP    (('T'<< 8) | 9)
  291. #define TIOCSTART    (('T'<< 8) | 10)
  292. #define TIOCGWINSZ    (('T'<< 8) | 11)
  293. #define TIOCSWINSZ    (('T'<< 8) | 12)
  294.  
  295. #define PPROCADDR    (('P'<< 8) | 1)
  296. #define PBASEADDR    (('P'<< 8) | 2)
  297.  
  298. /* terminal control constants */
  299. #define T_CRMOD        0x0001
  300. #define T_CBREAK    0x0002
  301. #define T_ECHO        0x0004
  302. #define T_RAW        0x0010
  303. #define T_TOS        0x0080
  304. #define T_TOSTOP    0x0100
  305.  
  306. /* the following are terminal status flags */
  307. #define TS_HOLD        0x1000        /* hold (e.g. ^S/^Q) */
  308. #define TS_COOKED    0x8000        /* interpret control chars */
  309.  
  310. /* structures for terminals */
  311. struct tchars {
  312.     char t_intrc;
  313.     char t_quitc;
  314.     char t_startc;
  315.     char t_stopc;
  316.     char t_eofc;
  317.     char t_brkc;
  318. };
  319.  
  320. struct ltchars {
  321.     char t_suspc;
  322.     char t_dsuspc;
  323.     char t_rprntc;
  324.     char t_flushc;
  325.     char t_werasc;
  326.     char t_lnextc;
  327. };
  328.  
  329. struct sgttyb {
  330.     char sg_ispeed;
  331.     char sg_ospeed;
  332.     char sg_erase;
  333.     char sg_kill;
  334.     unsigned short sg_flags;
  335. };
  336.  
  337. struct winsiz {
  338.     short    ws_row;
  339.     short    ws_col;
  340.     short    ws_xpixel;
  341.     short    ws_ypixel;
  342. };
  343.  
  344. struct tty {
  345.     short        pgrp;        /* process group of terminal */
  346.     short        state;        /* terminal status, e.g. stopped */
  347.     short        use_cnt;    /* number of times terminal is open */
  348.     short        res1;        /* reserved for future expansion */
  349.     struct sgttyb     sg;
  350.     struct tchars     tc;
  351.     struct ltchars     ltc;
  352.     struct winsiz    wsiz;
  353.     long        rsel;        /* selecting process for read */
  354.     long        wsel;        /* selecting process for write */
  355.     long        rsrvd[4];    /* reserved for future expansion */
  356. };
  357.  
  358. /* lock structure */
  359. struct flock {
  360.     short l_type;            /* type of lock */
  361. #define F_RDLCK        O_RDONLY
  362. #define F_WRLCK        O_WRONLY
  363. #define F_UNLCK        3
  364.     short l_whence;            /* SEEK_SET, SEEK_CUR, SEEK_END */
  365.     long l_start;            /* start of locked region */
  366.     long l_len;            /* length of locked region */
  367.     short l_pid;            /* pid of locking process
  368.                         (F_GETLK only) */
  369. };
  370.  
  371. /* defines for TOS attribute bytes */
  372. #ifndef FA_RDONLY
  373. #define           FA_RDONLY           0x01
  374. #define           FA_HIDDEN           0x02
  375. #define           FA_SYSTEM           0x04
  376. #define           FA_LABEL               0x08
  377. #define           FA_DIR               0x10
  378. #define           FA_CHANGED           0x20
  379. #endif
  380.  
  381. #endif _filesys_h
  382.